package com.example.controller;

import com.example.common.Result;
import com.example.entity.Record;
import com.example.service.RecordService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    private RecordService recordService;


    @PostMapping("/add")
    public Result add(@RequestBody Record record){
        System.out.println(record);
        recordService.add(record);
        return Result.success();
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5")Integer pageSize){
        System.out.println(pageNum);
        System.out.println(pageSize);
        PageInfo<Record> recordPageInfo = recordService.selectPage(pageNum, pageSize);
        return Result.success(recordPageInfo);

    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        System.out.println(id);
        recordService.delete(id);
        return Result.success();
    }
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        recordService.deleteBatch(ids);
        return Result.success();
    }
}
